package com.heima.article.listener;

import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.service.ApArticleConfigService;
import com.heima.common.constants.WmNewsMessageConstants;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 消息监听器
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class ArticlesDownListener {


    //
    private final ApArticleConfigService apArticleConfigService;

    /**
     * 监听上下架消息
     * @param map
     */
    @RabbitListener( bindings = @QueueBinding(
            value = @Queue(name = WmNewsMessageConstants.WM_NEWS_UP_OR_DOWN_TOPIC),
            exchange = @Exchange(name = WmNewsMessageConstants.WM_NEWS_EXCHANGE,type = ExchangeTypes.DIRECT)
    ))
    public void onMessage(Map<String,Object> map){

        if (map!=null){

            //修改文章配置
            apArticleConfigService.updateByMap(map);

            log.info("消息队列修改文章.....");

        }
    }



}















